package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import java.util.Set;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import com.example.framework.ApplicationManager;

public class TestBase {

	protected ApplicationManager app;
		
	//why afterclass? because each class must init link to itself every time 
	@BeforeClass
	public void setUp() throws Exception {
		// getInstance returns object app_manager which can be modified 
		// to work with parallel tests running.
		app = ApplicationManager.getInstance();
	}
	
	//need to find instance, and stop it.
	@AfterTest
	public void tearDown() throws Exception {
		ApplicationManager.getInstance().stop();
	}
	
	//we need to compare two sets - BEFORE and AFTER creation
	protected void verifyGroupAdded(Set<GroupObject> oldList,
			GroupObject validGroup, Set<GroupObject> newList) {
		assertThat(newList.size(), equalTo(oldList.size()+1));
		validGroup.setId("$$$");
		oldList.add(validGroup);
		validGroup.setId(null);
		assertThat(newList, equalTo(oldList));
	}

	protected void verifyGroupModified() {
		//do not know how to do it as for now :(
	}

	protected void verifyGroupDeleted(Set<GroupObject> oldList, 
			Set<GroupObject> newList) {
		assertThat(newList.size(), equalTo(oldList.size() - 1));
	}
}
